<template>
    <j-modal
      width="1000px"
      title="房间信息"
      :maskClosable="false"
      :destroyOnClose="true"
      :visible.sync="editModalVisible"
      @cancel="handleCancleDbSync"
    >
      <template slot="footer">
        <a-button @click="handleCancleDbSync">取消</a-button>
        <a-button type="primary" :loading="syncLoading" @click="handleDbSync">确定</a-button>
      </template>
      <!-- <a-form-model layout="inline" @keyup.enter.native="searchQuery">
        <a-form-model-item label="房源号">
          <a-input v-model="queryParam.houseCode" placeholder="请选择房源号"/>
        </a-form-model-item>
        <a-form-model-item label="房源类型">
          <j-dict-select-tag
            style="width:180px;"
            v-model="queryParam.houseType"
            placeholder="请选择房源类型"
            dict-code="park_housing_types"
          >
          </j-dict-select-tag>
        </a-form-model-item>
        <a-form-model-item>
          <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
          <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
        </a-form-model-item>
      </a-form-model> -->
      <vxe-grid
        ref="xTable"
        border
        resizable
        keep-source
        max-height="400px"
        align="center"
        :columns="columns"
        :data="dataSource"
        @checkbox-all="onSelectChange"
        @checkbox-change="onSelectChange"
      >
        <template v-slot:pager>
          <vxe-pager
            :layouts="layouts"
            :current-page.sync="ipagination.currentPage"
            :page-size.sync="ipagination.pageSize"
            :total="ipagination.total"
            @page-change="handlePageChange"
          >
          </vxe-pager>
        </template>
      </vxe-grid>
  </j-modal>
</template>
<script>
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import { filterObj } from '@/utils/util'
import { getAction } from '@/api/manage'
export default {
  name: 'HomeListModal',
  mixins: [VxeTableMixin],
  props: {
    contractCode: {
      type: String
    }
  },
  data() {
    return {
      editModalVisible: false,
      disableSubmit: false,
      syncLoading: false,
      url: {
        list: '/online/cgreport/api/getColumnsAndData/1501911706824585218'
      },
      columns: [
        { type: 'checkbox', width: 50 },
        { type: 'seq', width: 60 },
        { field: 'house_code', title: '房源号' },
        { field: 'project_name', title: '所属项目' },
        { field: 'building_name', title: '所属楼宇' },
        { field: 'floor', title: '所属楼层' },
        { field: 'building_area', title: '建筑面积' },
        { field: 'property_area', title: '产权面积' }
        // { field: 'houseType_dictText', title: '房源类型' }
      ],
      queryParam: {
        // houseStatus: '1,5'
      },
      isorter: {}
    }
  },
  methods: {
    show() {
      this.editModalVisible = true
      this.loadData()
    },
    handleCancleDbSync() {
      this.editModalVisible = false
    },
    handleDbSync() {
      if (this.selectionRows.length) {
        this.editModalVisible = false
        this.$emit('ok', this.selectionRows)
      } else {
        this.$message.warning('请选择房源')
      }
    },
    searchReset() {
      // this.queryParam = { houseStatus: '1,5' }
      this.loadData()
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams()// 查询条件
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.data.records
          this.ipagination.total = res.result.data.total
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    getQueryParams() {
      // 获取查询条件
      const sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      // const queryParam = { ...this.queryParam }
      // queryParam.houseCode = queryParam.houseCode ? '*' + queryParam.houseCode + '*' : undefined
      const queryParam = { self_contract_code: this.contractCode, contract_code: this.contract_code }
      var param = Object.assign(sqp, queryParam)
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.currentPage
      param.pageSize = this.ipagination.pageSize
      return filterObj(param)
    }
  }
}
</script>
<style lang="less">

</style>
